package com.ld.poetry.aigc.iflycode.laihg;

public class CodeGenerate {
    public static int lengthOfLIS(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int[] tails = new int[nums.length];
        int size = 0;
        for (int x : nums) {
            int i = 0, j = size;
            while (i != j) {
                int m = (i + j) / 2;
                if (tails[m] < x) {
                    i = m + 1;
                } else {
                    j = m;
                }
            }
            tails[i] = x;
            if (i == size) {
                ++size;
            }
        }
        return size;
    }


//    public static void main(String[] args) {
//        int[] nums = {10, 9, 2, 5, 3, 7, 101, 18};
//        System.out.println("最长增长子序列的长度为： " + lengthOfLIS(nums));
//    }

    public static void main(String[] args) {
        CodeGeneratorFactory factory = new CodeGeneratorFactory();
        CodeGenerator generator = factory.createCodeGenerator("Java");
        generator.generateCode();
    }
}

interface CodeGenerator {
    void generateCode();
}

class JavaCodeGenerator implements CodeGenerator {
    @Override
    public void generateCode() {
        System.out.println("Generating Java code...");
    }
}

class PythonCodeGenerator implements CodeGenerator {
    @Override
    public void generateCode() {
        System.out.println("Generating Python code...");
    }
}

class CodeGeneratorFactory {
    public CodeGenerator createCodeGenerator(String language) {
        if (language == null) {
            return null;
        }
        if (language.equalsIgnoreCase("Java")) {
            return new JavaCodeGenerator();
        } else if (language.equalsIgnoreCase("Python")) {
            return new PythonCodeGenerator();
        }
        return null;
    }
}
